function ret=G_l(G,l)
 if(l==1)
  ret={};
  for g = G
   g=g{1};
   ret{end+1}={g};
   ret{end+1}={g'};
  endfor
  return;
 endif
 
 ret={};
 prev= G_l(G,l-1);
 n=1;
 
 for gp = G
  gp=gp{1};
  for g = prev
   g=g{1};
   if(gp'==g{1})
    continue;
   endif
   ret{n}{1}=gp;
   for j =1 : l-1
    ret{n}{end+1}=g{j};
   endfor
   n=n+1;
  endfor 
  
  gp=gp';
  for g = prev
   g=g{1};
   if(gp'==g{1})
    continue;
   endif
   ret{n}{1}=gp;
   for j =1 : l-1
    ret{n}{end+1}=g{j};
   endfor
   n=n+1;
  endfor
 endfor
 
 ret=removeTrivialCases(ret);
endfunction

function ret=removeTrivialCases(Gl)
 l=0;
 j=1;
 while j <= length(Gl)-l; 
  g=Gl{j};
  while checkTrivial(g)==true
   Gl{j}=Gl{end-l};
   g=Gl{j};
   l=l+1;
  endwhile
  j=j+1;
 endwhile
 ret=Gl(1:end-l);
endfunction


function ret=checkTrivial(g)
 U=eye(2);
 for j =1:length(g)
  U=U*g{j};
  if (distance(U,eye(2))<1e-10) | (distance(U,-eye(2))<1e-10)
   ret=true;
   return;
  endif 
 endfor
 ret=false;
endfunction
